package Ldzy.Servlerts.com;
import Ldzy.bean.com.*;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;

public class PayServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session=request.getSession();
        response.setContentType("text/html;charset=utf-8");
        if(session.getAttribute("name")==null){
            response.getWriter().write("您还没有登录，不能打开支付页面！三秒后转向登录页面");
            response.setHeader("Refresh","3;URL=/Login.html");
        }else {
            List<Goods> goodses=(List<Goods>)session.getAttribute("cart");
            double total=0;
            int len=0;
            if(goodses==null){
                response.getWriter().write("<a href='/cart'>您还没有选购商品，请进入购物车选购商品<a/><br/>");
            }else {
                len=goodses.size();
                for (int i = 0; i <len ; i++) {
                    Goods goods=goodses.get(i);
                    total=total+goods.getPricer()*goods.getFase();
                }
                response.getWriter().write("请支付！金额为："+total);
            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            System.out.println("11");
    }
}